<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>实验室预约</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css">

    <script src="/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/webuploader/webuploader.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        layui.config({
            base : "/layui/js/"
        }).use(['form', 'layedit', 'laydate','table','common'], function(){
            var form = layui.form ,laydate = layui.laydate ,table = layui.table ,layer = layui.layer,layedit = layui.layedit,common = layui.common,$ = layui.$;
            laydate.render({
                elem: '#projectCreateYear'
                ,type: 'year'
            });
            laydate.render({
                elem: '#yearMonthDay'

            });
            laydate.render({
                elem: '#year'

            });
            /* form.render();//更新渲染表单*/
            //分页查询

            layui.use('table', function(){
                var table = layui.table;

                table.render({
                    elem: '#TableId',
                    id:'TableId',
                    even: true,
                    url: '/LabOrder/findLabOrderWithPage', //数据接口
                    limit:10,
                    limits:[10,20,30,50,100],
                    page: true ,//开启分页
                    cols: [[ //表头
                        {
                            field : 'loId',
                            title : 'Id',
                            type:   'checkbox',
                            width :  50

                        },{
                            field : 'loName',
                            title : '预约实验',
                            width :  200
                        },{
                            field : 'loTime',
                            title : '预约时间',
                            width :  100
                        },{
                            field : 'startTime',
                            title : '开始时间',
                            width :  100
                        },{
                            field : 'endTime',
                            title : '结束时间',
                            width :  200
                        },{
                            field : 'weekend',
                            title : '具体时间1',
                            width :  200
                        },{
                            field : 'time',
                            title : '具体时间2',
                            width :  200
                        },{
                            field : 'uName',
                            title : '预约人',
                            width :  120

                        },{
                            field : 'lName',
                            title : '预约实验室',
                            width :  150
                        },{
                            field : 'lRoom',
                            title : '实验室地址',
                            width :  150
                        },{
                            field : 'caName',
                            title : '所属班级',
                            width :  200
                        },{
                            field : 'clName',
                            title : '所属学院',
                            width :  200
                        },{
                            field : 'updateDate',
                            title : '修改日期'	,
                            width :  180
                        },{
                            field : 'addDate',
                            title : '添加日期'	,
                            width :  180
                        },{
                            field : 'approveState',
                            fixed : 'right',
                            title : '批准状态'	,
                            width :  100,
                            templet:'#lockState'
                        },{
                            field : 'aaa',
                            title : '操作',
                            fixed : 'right',
                            width:  280,
                            align:'center',
                            toolbar: '#barDemo'
                        }]]
                });

                //县级修改权限锁与解锁
                form.on('switch(checkDemo)', function(obj){
                    /*layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);*/
                    var flag = obj.elem.checked;
                    var loId = this.value;

                    if(flag==true){
                        var lockState = "0";
                        layer.confirm('确定要通过预约吗？', {
                            title: '通过预约',
                            resize: false,
                            btn: ['确定', '取消'],
                            btnAlign: 'c',
                            anim:1,
                            icon: 3
                        }, function () {
                            $.ajax({
                                url : "/LabOrder/changeLockState",
                                type : 'post',
                                async: false,
                                data :  {'loId':loId,'lockState':lockState},
                                success : function(data) {
                                    if(data.returnCode == 0000){
                                        top.layer.msg("预约通过", {icon: 6});
                                        location.reload();
                                    }else{
                                        top.layer.msg("该预约已通过",{icon: 5});
                                        location.reload();
                                    }
                                },error:function(){

                                }
                            });

                        }, function () {
                            location.reload();
                        })
                    }else if(flag==false){
                        layer.confirm('确定要取消预约吗？', {
                            title: '取消预约',
                            resize: false,
                            btn: ['确定', '取消'],
                            btnAlign: 'c',
                            anim:1,
                            icon: 3
                        }, function () {
                            $.ajax({
                                url : "/LabOrder/removeLockState",
                                type : 'post',
                                async: false,
                                data :  {'loId':loId,'lockState':lockState},
                                success : function(data) {
                                    if(data.returnCode == 0000){
                                        top.layer.msg("预约取消成功", {icon: 6});
                                        location.reload();
                                    }else{
                                        top.layer.msg("该预约已取消",{icon: 5});
                                        location.reload();
                                    }
                                },error:function(){

                                }
                            });

                        }, function () {
                            location.reload();
                        })
                    }
                });

                //工具按钮

                table.on('tool(TableId)', function(obj) {  //注：tool是工具条事件名，TableId是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data//获得当前行数据
                    var layEvent = obj.event; //获得 lay-event 对应的值
                    if (layEvent === 'detail') { //查看
                        var loId = data.loId;

                        var url = "/LabOrder/toLabOrderDetail?loId=" + loId;

                        common.cmsLayOpen('实验室预约查看', url, '1500px', '700px');



                    }else if (layEvent === 'del') { //删除

                        var data1 = data.loId;
                        layer.confirm('你确定要删除吗？', {
                            title: '删除',
                            resize: false,
                            btn: ['确定', '取消'],
                            btnAlign: 'c',
                            anim:1,
                            icon: 3
                        }, function () {
                            debugger;
                            $.ajax({
                                url : "/LabOrder/delLabOrderInfo",
                                type : 'post',
                                async: false,
                                data :  {'loId':data1},
                                success : function(flag) {
                                    if(flag == true){
                                        debugger;
                                        top.layer.msg("删除成功", {icon: 6});
                                        obj.del(); //删除对应行（tr）的DOM结构
                                        location.reload();
                                    }else if(flag == false){
                                        top.layer.msg("该项目已添加在计划管理或项目管理列表中，无法删除！",{icon: 5,
                                            time:5000
                                        });
                                        location.reload();
                                    }
                                },error:function(){

                                }
                            });
                        }, function () {
                            layer.msg('关闭', {
                                time: 1000, //1秒后自动关闭
                            });
                        });


                    }else if (layEvent === 'edit') { //编
                        var loId = data.loId;
                        // var lockState = data.lockState;
                        // var loginName = $("#loginName").val();
                        // if(loginName == null||loginName == ""&&lockState=="0"){
                        //     alert('您没有修改权限,请联系管理员！');
                        // }else{
                            var url = "/LabOrder/toLabOrderEdit?loId=" + loId;

                            common.cmsLayOpen('实验室预约修改', url, '1500px', '700px');
                        // }


                    }else if(layEvent === 'down'){//预约失败
                        var loId = data.loId;
                        $.ajax({
                            url : "/LabOrder/labOrderDown",
                            type : 'post',
                            async: false,
                            data :  {'loId':loId},
                            success : function(flag) {
                                if(flag.returnCode == 0000){
                                    top.layer.msg("标记为预约失败！", {icon: 6});
                                    obj.del(); //删除对应行（tr）的DOM结构
                                    location.reload();
                                }else if(flag.returnCode == 1111){
                                    top.layer.msg("出错啦",{icon: 5,
                                        time:5000
                                    });
                                    location.reload();
                                }
                            },error:function(){

                            }
                        });
                    }

                });
                /**查询*/
                $(".search_btn").click(function(){
                    var loading = layer.load(0,{ shade: [0.3,'#000']});
                    //监听提交

                    table.reload('TableId',{
                        where: {
                            cName:$('#searchName').val(),
                            uName:$('#searchuName').val(),
                            lName:$('#searchlName').val(),
                            loTime:$('#loTime').val()
                        },
                        page: true,
                        done: function (res, curr, count) {
                            common.resizeGrid();
                            layer.close(loading);

                        }
                    });
                });
                //导出
                $(".excel_btn").click(function()
                { //获取选中数据

                    var checkStatus = table.checkStatus('TableId')
                            , data = checkStatus.data;

                    if (data.length == 0) {
                        $.post("/project/excelProject", {"pIds[]": null}, function (data) {

                            if (data.code == 200) {
                                window.location.href = "/upload/excel/project.xls";
                                layer.msg('下载全部数据成功！', {
                                    time: 500,
                                });

                            } else {
                                layer.msg('下载失败,请联系管理员', {
                                    time: 5000,
                                });
                            }
                        })
                        return;
                    } else {
                        var excelList = [];
                        for (var i in data) {
                            excelList.push(data[i].projectCreateId);
                        }
                        layer.confirm('是否要导出选择项？', {
                            btn: ['确定', '取消'] //按钮
                        }, function () {
                            debugger;
                            $.post("/project/excelProject", {"pIds[]": excelList}, function (data) {

                                if (data.code == 200) {
                                    window.location.href = "/upload/excel/project.xls";
                                    layer.msg('下载成功！', {
                                        time: 500,
                                    });

                                } else {
                                    layer.msg('下载失败,请联系管理员', {
                                        time: 5000,
                                    });
                                }
                            })
                        }, function () {
                            layer.msg('关闭', {
                                time: 1000, //1秒后自动关闭
                            });
                        });

                    }

                });
            });
            /**表单回显方法*/
            function standardDetail(data) {
                debugger;
                var $ = layui.$;
                console.log(Object.entries(data));
                //回显表单数据
                for (var i = 0; i < Object.entries(data).length; i++) {
                    var id = '#' + Object.entries(data)[i][0];
                    var text = Object.entries(data)[i][1];
                    if(text==null){
                        text = '';
                    }
                    $(id).text(text);
                }
                var index = layer.open({
                    type: 1, //页面层
                    area: ['700px', '600px'],
                    title: ['项目详情', 'font-size:18px;text-align:center;'],
                    closeBtn: 1,
                    offset: '0px',
                    content: $('#showStandard'),
                    anim: 1,
                    btn: '确   定',
                    btnAlign: 'c', //确定按钮剧中
                    /**确定按钮触发事件两个参数，分别为当前层索引、当前层DOM对象*/
                    yes: function (index, layero) {
                        layer.close(index); //如果设定了yes回调，需进行手工关闭
                    },
                    /**右上角关闭按钮事件*/
                    cancel: function (index, layero) {
                        layer.close(index)
                    }
                });
            };




            //批量删除

            var $ = layui.$, active = {
                delCheckData: function () { //获取选中数据
                    var checkStatus = table.checkStatus('TableId')
                            , data = checkStatus.data;

                    if (data.length == 0) {
                        layer.msg('请选择要删除的数据！', {
                            time: 1000,
                        });
                        return;
                    } else {
                        var delList = [];
                        for (var i in data) {
                            delList.push(data[i].loId);
                        }
                        layer.confirm('你确定要删除吗？', {
                            btn: ['确定', '返回'] //按钮
                        }, function () {
                            $.post("/LabOrder/delManyLabOrderInfo", {"loIds[]": delList}, function (flag) {
                                if (flag==true) {
                                    layer.msg('删除成功！', {
                                        time: 500,
                                    });
                                    table.reload("TableId")
                                }else if(flag==false){
                                    layer.msg('删除失败，该项目在计划年度或项目年度中存在，无法删除！！', {
                                        time: 5000,
                                    });
                                }
                            })
                        }, function () {
                            layer.msg('关闭', {
                                time: 1000, //1秒后自动关闭
                            });
                        });
                    }


                },
                //拷贝功能
                copyData: function () { //获取选中数据
                    var checkStatus = table.checkStatus('TableId')
                            , data = checkStatus.data;

                    if (data.length == 0) {
                        layer.msg('请选择要拷贝的项目数据！', {
                            time: 1000,
                        });
                        return;
                    } else {
                        var copyList = [];
                        for (var i in data) {
                            copyList.push(data[i].projectCreateId);
                        }
                        layer.confirm('请选择您要拷贝的路径', {
                            btn: ['年度计划管理', '年度项目管理'] //按钮
                        }, function () {
                            layer.confirm('请输入年份。 <input type="text" name="date1" id="year" autocomplete="off" class="layui-input">',function(){
                                var date1=$(" input[ name='date1' ] ").val();
                                $.post("/project/copyProjectInfoToPlan", {"pIds[]": copyList,"date1": date1}, function (data) {
                                    if (data.returnCode == 0000) {
                                        layer.msg('拷贝成功！', {
                                            time: 500,
                                        });
                                        f
                                    } else {
                                        layer.msg('您拷贝的项目中包含计划管理中已存在的项目，拷贝失败!', {
                                            time: 5000,
                                        });
                                    }
                                })
                            })

                        }, function () {
                            layer.confirm('请输入年份，将拷贝的数据列为改年度项目。 <input type="text" name="date1"  autocomplete="off" class="layui-input">',function(){
                                var date1=$(" input[ name='date1' ] ").val();
                                $.post("/project/copyProjectInfoToAnnual", {"pIds[]": copyList,"date1": date1}, function (data) {
                                    if (data.returnCode == 0000) {
                                        layer.msg('拷贝成功！', {
                                            time: 500,
                                        });
                                    }else if (data.returnCode == 1111) {
                                        layer.msg('该项目为前期项目，无法添加至年度项目！', {
                                            time: 5000,
                                        });
                                    }else {
                                        layer.msg('您拷贝的项目中包含项目管理中已存在的项目，拷贝失败!', {
                                            time: 5000,
                                        });
                                    }
                                })
                            })

                        });
                    }
                },
                //复制
                copyData1: function () { //获取选中数据
                    var checkStatus = table.checkStatus('TableId')
                            , data = checkStatus.data;

                    if (data.length == 0) {
                        layer.msg('请选择要复制的项目数据！', {
                            time: 1000,
                        });
                        return;
                    }else if (data.length > 1) {
                        layer.msg('只能选择一条数据进行复制！', {
                            time: 1000,
                        });
                        return;
                    } else {
                        var copyList = [];
                        for (var i in data) {
                            copyList.push(data[i].projectCreateId);
                        }
                        layer.confirm('您确定要将选中的数据复制到项目库吗?', {
                            btn: ['确定', '返回'] //按钮
                        }, function () {
                            debugger;
                            $.post("/project/copyProjectInfoToProject", {"pIds[]": copyList}, function (data) {
                                if (data.returnCode == 0000) {
                                    layer.msg('复制成功！', {
                                        time: 500,
                                    });
                                    location.reload();
                                }
                            })
                        }, function () {
                            layer.msg('关闭', {
                                time: 1000, //1秒后自动关闭
                            });
                        });
                    }
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        })

    </script>
    <script type="text/html" id="barDemo">

        <a class="layui-btn layui-btn-sm" lay-event="detail">查看</a>
        <shiro:hasAnyRoles name="SUPERADMIN">
            <a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon"></i></a>

        </shiro:hasAnyRoles>

        <shiro:hasAnyRoles name="SUPERADMIN,CITY,CITY00,CITY01,CITY02,CITY03,CITY04,CITY05,CITY06,CITY07,CITY08,CITY09">
            <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon"></i></a>
        </shiro:hasAnyRoles>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="down"><i class="layui-icon">&#x1006;</i></a>
        <shiro:hasAnyRoles name="SUPERADMIN,CITY,CITY00,CITY01,CITY02,CITY03,CITY04,CITY05,CITY06,CITY07,CITY08,CITY09">
            <input type="checkbox" name="check" value="{{d.loId}}"  lay-skin="switch"  lay-text="通过|取消" lay-filter="checkDemo" {{ d.lockState == 1 ? 'checked' : '' }}>
        </shiro:hasAnyRoles>
    </script>
    <script type="text/html" id="lockState">
        {{#  if(d.lockState === '1'){ }}
        <span style="color: #00A600;">{{ "预约成功" }}</span>
        {{#  } else if(d.lockState === '-1'){ }}
        <span style="color: red;">{{ "预约失败" }}</span>
        {{#  } else { }}
        <span style="color: #3399FF;">{{ "正在预约" }}</span>
        {{#  } }}
    </script>
</head>
<body>
<#--条件查询模块-->
<form class="layui-form layui-form-pane"  method="post" lay-filter="SearchFilter"  >
    <!-- 日期选择 -->
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">预约实验</label>
            <div class="layui-input-inline">
                <input type="text" id="searchName" name="searchContent" placeholder="输入名称 "  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">预约人</label>
            <div class="layui-input-inline">
                <input type="text" id="searchuName" name="searchuName" placeholder="输入名称 "  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">预约实验室</label>
            <div class="layui-input-inline">
                <select id="searchlName"  name="searchlName" value="">
                    <option value="">请选择</option>
                    <#list labsList as l>
                    <option value="${l.lId}">${l.lName}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所属学院</label>
            <div class="layui-input-inline">
                <select id="courseLab"  name="lId" value="">
                    <option value="">请选择</option>
                    <#list collegeList as college>
                            <option value="${college.clId}">${college.clName}</option>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">预约时间</label>
            <div class="layui-input-inline">
                <input type="text" name="loTime" class="layui-input" id="loTime" placeholder="点击选择日期 ">
            </div>
        </div>
        <div class="layui-inline">
            <a class="layui-btn search_btn" lay-submit id="search_btn" lay-submit="" lay-filter="search">查询</a>
        </div>
        <div class="layui-inline" >
            <a class="layui-btn layui-btn-normal" href="/LabOrder/getAddLabOrder">添加</a>
        </div>
        <div class="layui-inline">
            <a class="layui-btn excel_btn" id="excel_btn">数据导出</a>
        </div>
    </div>
</form>
<input type="hidden" value="${loginName}" id="loginName">
<div class="layui-btn-group demoTable" style="margin-bottom: -10px;">
    <shiro:hasAnyRoles name="SUPERADMIN">
        <button class="layui-btn" data-type="delCheckData">批量删除</button>
    </shiro:hasAnyRoles>
</div>
<table class="layui-table-cell" id="TableId" lay-filter="TableId" lay-data="{id: 'TableId'} skin: 'row'" ></table>

<div id="uploader" class="wu-example" style="display: none;text-align: center;padding: 15px;">
    <!--用来存放文件信息-->
    <div id="filelist" class="uploader-list"></div>
    <div class="btns" style="display: flex;flex-direction: row;align-items: center;justify-content: center">
        <button id="picker" class="btn btn-default" style="width:90px;height:43px;background-color: #00b7ee;color:#fff;margin-right: 5px;">选择文件</button>
        <button id="ctlBtn" class="btn btn-default" style="width:90px;height:43px;background-color: #00b7ee;color:#fff;margin-left:5px;">开始上传</button>

    </div>
</div>
<div style="margin-bottom: 250px"></div>
</body>
</html>
